#ifndef _REACTOR_H_
#define _REACTOR_H_
#include "EventArgs.h"
#include <memory>
#include "ReactorDef.h"
#include "ReactorTypeDef.h"
class CombatSessionImp;
class CombatCard;
class AffectorBase;
class Validator;
class Selector;
class EventConditionBase;
class CombatObj;

class  Reactor
{
	friend class ReactorPool;
public:
	enum EExcludeCheck
	{
		EExcludeCheck_Coexist,
		EExcludeCheck_Reject,
		EExcludeCheck_ReplaceMe,
	};
	Reactor(const ReactorDef* pDef );
	
	bool OnEvent(EventArgBase& rEventArgs);
	bool OnEvent_Process(EventArgBase& rEventArgs);
	bool OnEvent_PreCheck(EventArgBase& rEventArgs);
	const Validator* GetValidator()const;
	const EventConditionBase* GetEventCondition()const;
	const std::vector<const Affection*>& GetAffections() const;

	int32 GetID()const {return m_iID;}
	int32 GetType() const;
	const ReactorTypeDef* GetTypeDef() const;
	const std::vector<int32>& GetCategorys() const;
	int32 GetDefID() const { return m_iDefID;}
	const ReactorDef * GetDef() const { return m_pDef;}
	void SetOwner(CombatObj * pOwner){m_pOwner=pOwner;}
	CombatObj * GetOwner() const { return m_pOwner;}
	
	void SetSender(int32 iSenderID){m_iSenderID=iSenderID;}
	int32 GetSenderID() const { return m_iSenderID;}

	EExcludeCheck ReactorExcludCheck(const ReactorDef *pDef,uint8 iSender);

	void IncLifeTurn();
	int32 GetLifeTurn()const{ return m_iLifeTurn ;}
	bool IsExpired();
	bool IsForceRemoved() const {return m_bForceRemoved;}
	void ForceRemove(){ m_bForceRemoved=true;}
	std::string GetDisplayName()const;

	void ResolveDef();
private:	
	int32 m_iID;
	int32 m_iDefID;
	const ReactorDef * m_pDef;
	CombatObj * m_pOwner;
	int32 m_iSenderID;
	uint32 m_iLifeTurn;
	bool	m_bForceRemoved;

};

class ReactorHolder
{
public :
	ReactorHolder(){}
	~ReactorHolder();
	void SetPool(ReactorPool * pPool){ m_pReactorPool=pPool;}
	Reactor* ReactorAt(uint32 iIndex) const;
	Reactor* LookupReactor(int32 iID);
	uint32 Count() const { return m_vReactors.size();}
	Reactor* AddNew(const ReactorDef* pDef,uint8 iSenderID);
	bool ClearOne(Reactor *pReactor);
	bool ClearOneByID(int32 iID);
	void ClearAll();
	void SetOwner(CombatObj * pOwner)
	{
		m_pOwner=pOwner;
	}
private:
	std::vector<Reactor*> m_vReactors;
	ReactorPool *m_pReactorPool;
	CombatObj * m_pOwner;
};


#endif